package com.mozz.finally_work.servlet;

import com.mozz.finally_work.dao.SubscribeDao;
import com.mozz.finally_work.pojo.User;
import com.mozz.finally_work.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "UserSubscribeServlet", value = "/UserSubscribeServlet")
public class UserSubscribeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*获取参数*/
        String userId = request.getParameter("userId");
        /*调用dao查询*/
        SqlSession session = MybatisUtils.getSession();
        SubscribeDao dao = session.getMapper(SubscribeDao.class);
        List<User> users = dao.querySubscribeUsers(userId);
        /*请求转发*/
        session.close();
        request.setAttribute("subscribes",users);
        request.getRequestDispatcher("user_subscribe.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
